package cn.hxzy.controller;
import cn.hxzy.response.R;
import cn.hxzy.service.impl.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class FileUploadController {

    private final OssService ossService;

    @Autowired
    public FileUploadController(OssService ossService) {
        this.ossService = ossService;
    }

    @PostMapping("/upload")
    public R uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
        String fileName = ossService.uploadFile(file);
        return R.success(fileName);
    }
}
